Skip to content

Conversation

@mdickinson
Copy link
Member

@mdickinson mdickinson commented Aug 15, 2021

PR #27278 fixed undefined behaviour in complex exponentiation, but also changed the behaviour for exponentiations whose exponent was a small integer but not actually an int, for example as in (3+4j)**2.0. In particular, the overflow behaviour for these expressions changed:

Prior to #27278:

>>> complex("infj")**2
(nan+nanj)
>>> complex("infj")**2.0
(nan+nanj)

After #27278 :

>>> complex("infj")**2
(nan+nanj)
>>> complex("infj")**2.0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: complex exponentiation

This PR restores the old behaviour, but does not re-introduce the undefined behaviour fixed by the original PR.

https://bugs.python.org/issue44698

{
Py_complex cn;

if (n > 100 || n < -100) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This branch is now redundant: the bounds check is performed in the code that calls c_powi.

@miss-islington
Copy link
Contributor

Thanks @mdickinson for the PR 🌮🎉.. I'm working now to backport this PR to: 3.9, 3.10.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-27796 is a backport of this pull request to the 3.10 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.10 only security fixes label Aug 17, 2021
@bedevere-bot
Copy link

GH-27797 is a backport of this pull request to the 3.9 branch.

@mdickinson
Copy link
Member Author

@gpshead Thank you for the review!

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Aug 17, 2021
…pythonGH-27772)

(cherry picked from commit 4b9a2dc)

Co-authored-by: Mark Dickinson <mdickinson@enthought.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Aug 17, 2021
…pythonGH-27772)

(cherry picked from commit 4b9a2dc)

Co-authored-by: Mark Dickinson <mdickinson@enthought.com>
mdickinson added a commit that referenced this pull request Aug 17, 2021
…GH-27772) (GH-27796)

(cherry picked from commit 4b9a2dc)

Co-authored-by: Mark Dickinson <mdickinson@enthought.com>
mdickinson added a commit that referenced this pull request Aug 17, 2021
…GH-27772) (GH-27797)

(cherry picked from commit 4b9a2dc)

Co-authored-by: Mark Dickinson <mdickinson@enthought.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants